package com.reza.simpd.components.datagridutils
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.CheckBox;
	import mx.controls.dataGridClasses.DataGridColumn;
	
	public class ComponentCheckBoxReferencingDGColumn extends CheckBox
	{
		
		private var _dgColumn:DataGridColumn;
		
		public function ComponentCheckBoxReferencingDGColumn()
		{
			super();
			selected = true;
			addEventListener(MouseEvent.CLICK, componentClicked);			
		}

		[Bindable(event="dgColumnChanged")]
		public function get dgColumn():DataGridColumn
		{
			return this._dgColumn;
		}

		public function set dgColumn(value:DataGridColumn):void
		{
			_dgColumn = value;
			this.label = value.headerText;
			dispatchEvent(new Event("dgColumnChanged"));
		}

		public function componentClicked(event:MouseEvent):void
		{
			if (dgColumn != null)
				dgColumn.visible = this.selected;
		}
	}
}